﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.quest.Managers {
    import Engine.Classes.*;
    import Engine.Transactions.*;
    import flash.utils.*;
    import Classes.*;
    import Transactions.*;
    import GameMode.*;
    import Classes.doobers.*;
    import Modules.zoo.*;
    import Modules.quest.Helpers.*;
    import Modules.franchise.transactions.*;
    import Mechanics.Transactions.*;
    import Modules.bandits.transactions.*;
    import Modules.trains.*;
    import Transactions.train.*;
    import Modules.minigames.transactions.*;

    public class GameQuestUtility {

        public static function countNewNeighbors(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            var _local6:String;
            var _local7:int;
            var _local8:int;
            var _local9:int;
            var _local10:String;
            var _local11:Boolean;
            var _local12:String;
            var _local4:int;
            if (((((((!(_arg3)) || (!(_arg3.hasOwnProperty("neighbors"))))) || (!(_arg3.hasOwnProperty("total"))))) || (!(_arg3.hasOwnProperty("max"))))){
                return (0);
            };
            var _local5:int;
            for each (_local6 in _arg3.neighbors) {
                if (_local6 == null){
                } else {
                    _local5++;
                };
            };
            _local7 = Math.max((_arg3.max - _local5), 0);
            _local8 = Math.min(_local7, _arg3.total);
            _local9 = (_arg3.total - _local8);
            for each (_local10 in Global.player.neighbors) {
                _local11 = true;
                if (_local10 == Player.FAKE_USER_ID_STRING){
                } else {
                    for each (_local12 in _arg3.neighbors) {
                        if (_local12 == _local10){
                            _local11 = false;
                        };
                    };
                    if (_local11){
                        _local9++;
                    };
                };
            };
            return (Math.min(_local9, _arg3.total));
        }
        public static function getFriendVisitReplayObject(_arg1:Class, _arg2:Transaction, _arg3:Object=null):WorldObject{
            var _local4:TRedeemVisitorHelpAction = (_arg2 as TRedeemVisitorHelpAction);
            var _local5:WorldObject = _local4.getWorldObject();
            if (_local4.getEquivalentTransaction(_local5) != _arg1){
                return (null);
            };
            return (_local5);
        }
        public static function countPeddlerTransactionByClassHelper(_arg1:Class, _arg2:Transaction, _arg3:String):int{
            if (!(_arg2 is _arg1)){
                return (0);
            };
            var _local4:WorldObject;
            if ((_arg2 is TRedeemVisitorHelpAction)){
                _local4 = getFriendVisitReplayObject(_arg1, _arg2);
            } else {
                if (!(_arg2 is TPlacePeddlerAtFakeUser)){
                    throw (new Error((("Quest error: tested transaction " + _arg1) + " is not a world state transaction!")));
                };
                _local4 = (_arg2 as TPlacePeddlerAtFakeUser).getWorldObject();
            };
            if (!_local4){
                return (0);
            };
            var _local5 = (("[object " + _arg3) + "]");
            return (((String(_local4))==_local5) ? 1 : 0);
        }
        public static function countTransactionByClassHelper(_arg1:Class, _arg2:Transaction, _arg3:String):int{
            if (!(((_arg2 is _arg1)) || ((_arg2 is TRedeemVisitorHelpAction)))){
                return (0);
            };
            var _local4:WorldObject;
            if ((_arg2 is TRedeemVisitorHelpAction)){
                _local4 = getFriendVisitReplayObject(_arg1, _arg2);
            } else {
                if (!(_arg2 is TWorldState)){
                    throw (new Error((("Quest error: tested transaction " + _arg1) + " is not a world state transaction!")));
                };
                _local4 = (_arg2 as TWorldState).getWorldObject();
            };
            if (!_local4){
                return (0);
            };
            var _local5 = (("[object " + _arg3) + "]");
            return (((String(_local4))==_local5) ? 1 : 0);
        }
        public static function countTransactionByNameHelper(_arg1:Class, _arg2:Transaction, _arg3:String):int{
            var _local6:WorldObject;
            if (!(((_arg2 is _arg1)) || ((_arg2 is TRedeemVisitorHelpAction)))){
                return (0);
            };
            var _local4:Object;
            if ((_arg2 is TRedeemVisitorHelpAction)){
                _local6 = getFriendVisitReplayObject(_arg1, _arg2);
                if (_local6){
                    _local4 = _local6.getSaveObject();
                };
            } else {
                _local4 = (_arg2 as TWorldState).getSaveObject();
            };
            if (!_local4){
                return (0);
            };
            var _local5:String = _local4.itemName;
            return ((findNameInNames(_local5, _arg3)) ? 1 : 0);
        }
        public static function countConstructionTransactionByNameHelper(_arg1:Class, _arg2:Transaction, _arg3:String):int{
            if (!(((_arg2 is _arg1)) || ((_arg2 is TRedeemVisitorHelpAction)))){
                return (0);
            };
            var _local4:WorldObject;
            if ((_arg2 is TRedeemVisitorHelpAction)){
                _local4 = getFriendVisitReplayObject(_arg1, _arg2);
            } else {
                _local4 = (_arg2 as TWorldState).getWorldObject();
            };
            if (!_local4){
                return (0);
            };
            var _local5:ConstructionSite = (_local4 as ConstructionSite);
            if (_local5 == null){
                return (0);
            };
            var _local6:String = _local5.targetName;
            return ((findNameInNames(_local6, _arg3)) ? 1 : 0);
        }
        public static function countTransactionByContractNameHelper(_arg1:Class, _arg2:Transaction, _arg3:String):int{
            var _local6:WorldObject;
            if (!(((_arg2 is _arg1)) || ((_arg2 is TRedeemVisitorHelpAction)))){
                return (0);
            };
            var _local4:Object;
            if ((_arg2 is TRedeemVisitorHelpAction)){
                _local6 = getFriendVisitReplayObject(_arg1, _arg2);
                if (_local6){
                    _local4 = _local6.getSaveObject();
                };
            } else {
                _local4 = (_arg2 as TWorldState).getSaveObject();
            };
            var _local5:String = _local4.contractName;
            return ((findNameInNames(_local5, _arg3)) ? 1 : 0);
        }
        protected static function findNameInNames(_arg1:String, _arg2:String):Boolean{
            var _local3:String;
            for each (_local3 in breakApartNames(_arg2)) {
                if (_arg1 == _local3){
                    return (true);
                };
            };
            return (false);
        }
        protected static function breakApartNames(_arg1:String):Array{
            var _local2:Array = _arg1.split(",");
            return (_local2);
        }
        public static function clearByClass(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (countTransactionByClassHelper(TClear, _arg1, _arg2));
        }
        public static function sellByClass(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (countTransactionByClassHelper(TSell, _arg1, _arg2));
        }
        public static function sellByName(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (countTransactionByNameHelper(TSell, _arg1, _arg2));
        }
        public static function moveByClass(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (countTransactionByClassHelper(TMove, _arg1, _arg2));
        }
        public static function moveByName(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (countTransactionByNameHelper(TMove, _arg1, _arg2));
        }
        public static function upgradeItemByName(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (countTransactionByNameHelper(TUpgradeBuilding, _arg1, _arg2));
        }
        public static function placeByClass(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (countTransactionByClassHelper(TPlaceMapResource, _arg1, _arg2));
        }
        public static function placeBuildingByName(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (countTransactionByNameHelper(TPlaceMapResource, _arg1, _arg2));
        }
        public static function placePeddlerByClass(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (countPeddlerTransactionByClassHelper(TPlacePeddlerAtFakeUser, _arg1, _arg2));
        }
        public static function harvestByClass(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (countTransactionByClassHelper(THarvest, _arg1, _arg2));
        }
        public static function harvestBusinessByClass(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (countTransactionByClassHelper(THarvestBusiness, _arg1, _arg2));
        }
        public static function harvestResidenceByName(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (countTransactionByNameHelper(THarvest, _arg1, _arg2));
        }
        public static function harvestPlotByName(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (countTransactionByContractNameHelper(THarvest, _arg1, _arg2));
        }
        public static function harvestBusinessByName(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (countTransactionByNameHelper(THarvestBusiness, _arg1, _arg2));
        }
        public static function startContractByClass(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (countTransactionByClassHelper(TFactoryContractStart, _arg1, _arg2));
        }
        public static function startContractByName(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (countTransactionByContractNameHelper(TFactoryContractStart, _arg1, _arg2));
        }
        public static function openBusinessByClass(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (countTransactionByClassHelper(TOpenBusiness, _arg1, _arg2));
        }
        public static function openBusinessByCommodityType(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (countTransactionByCommodityUsedHelper(_arg1, _arg2));
        }
        public static function openBusinessByName(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (countTransactionByNameHelper(TOpenBusiness, _arg1, _arg2));
        }
        public static function finishConstructionByName(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (countConstructionTransactionByNameHelper(TConstructionFinish, _arg1, _arg2));
        }
        public static function transferFromStorageToDisplay(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            var _local4:TMechanicDataTransfer;
            var _local5:Object;
            var _local6:String;
            if ((_arg1 is TMechanicDataTransfer)){
                _local4 = (_arg1 as TMechanicDataTransfer);
                if (((_local4.params) && ((_local4.params.length > 0)))){
                    for each (_local5 in _local4.params) {
                        _local6 = _local4.getOwner().getItemName();
                        if ((((((_local5["source"] == ZooManager.MECHANIC_STORAGE)) && ((_local5["dest"] == ZooManager.MECHANIC_SLOTS)))) && ((_arg2 == _local6)))){
                            return (1);
                        };
                    };
                };
            };
            return (0);
        }
        public static function storeItemInMechanicUser(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            var _local4:TMechanicAction;
            var _local5:Object;
            var _local6:String;
            if ((_arg1 is TMechanicAction)){
                _local4 = (_arg1 as TMechanicAction);
                _local5 = (_arg1 as TMechanicAction).getParams();
                if (_local5){
                    if (_arg2 == _local4.ownerObject.getItem().type){
                        for (_local6 in _local5) {
                            if ((((_local5[_local6] == "storeObject")) && ((_local6 == "operation")))){
                                return (1);
                            };
                        };
                    };
                };
            };
            return (0);
        }
        public static function finishMiniGameByName(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            if ((_arg1 is TMiniGameComplete)){
                return ((((_arg1 as TMiniGameComplete).getGameName() == _arg2)) ? 1 : 0);
            };
            return (0);
        }
        public static function renameCity(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (((_arg1 is TRenameCity)) ? 1 : 0);
        }
        public static function onValidCityName(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (((_arg1 is TOnValidCityName)) ? 1 : 0);
        }
        public static function seenQuest(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (((((_arg1 is TSeenQuest)) && (((_arg1 as TSeenQuest).m_questName == _arg2)))) ? 1 : 0);
        }
        public static function popNews(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (((((_arg1 is TPopNews)) && (((_arg1 as TPopNews).m_questName == _arg2)))) ? 1 : 0);
        }
        public static function neighborVisit(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            if ((_arg1 is TInitialVisit)){
                if ((((((_arg2 == "")) || ((_arg2 == null)))) || ((_arg2 == (_arg1 as TInitialVisit).recipientId)))){
                    return (1);
                };
            };
            return (0);
        }
        public static function uniqueNeighborVisit(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            var _local4:String;
            var _local5:int;
            var _local6:int;
            var _local7:String;
            var _local8:int;
            if ((_arg1 is TInitialVisit)){
                _local4 = (_arg1 as TInitialVisit).recipientId;
                _local5 = int(_arg2);
                _local6 = int((GlobalEngine.getTimer() / 1000));
                if (((!(_arg3)) || (!(_arg3.hasOwnProperty("neighborsVisited"))))){
                    _arg3.neighborsVisited = new Array();
                    _arg3.neighborsVisited[_local4] = _local6;
                    return (1);
                };
                for (_local7 in _arg3.neighborsVisited) {
                    if (_local7 == _local4){
                        _local8 = _arg3.neighborsVisited[_local7];
                        if ((_local6 - _local8) < _local5){
                            return (0);
                        };
                    };
                };
                _arg3.neighborsVisited[_local4] = _local6;
                return (1);
            };
            return (0);
        }
        public static function harvestNeighborResidenceByName(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (countNeighborVisitActionHelper(VisitorHelpType.RESIDENCE_COLLECT_RENT, _arg1, _arg2));
        }
        public static function sendTourNeighborBusinessByName(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (countNeighborVisitActionHelper(VisitorHelpType.BUSINESS_SEND_TOUR, _arg1, _arg2));
        }
        public static function reviveNeighborPlotByName(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            var _local4:int = (countNeighborVisitActionHelper(VisitorHelpType.PLOT_REVIVE, _arg1, _arg2) + countNeighborVisitActionHelper(VisitorHelpType.SHIP_REVIVE, _arg1, _arg2));
            return (_local4);
        }
        public static function waterNeighborPlotByName(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            var _local4:int = (countNeighborVisitActionHelper(VisitorHelpType.PLOT_WATER, _arg1, _arg2) + countNeighborVisitActionHelper(VisitorHelpType.SHIP_WATER, _arg1, _arg2));
            return (_local4);
        }
        public static function harvestNeighborPlotByName(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            var _local4:int = (countNeighborVisitActionHelper(VisitorHelpType.PLOT_HARVEST, _arg1, _arg2) + countNeighborVisitActionHelper(VisitorHelpType.SHIP_HARVEST, _arg1, _arg2));
            return (_local4);
        }
        public static function countNeighborVisitActionHelper(_arg1:String, _arg2:Transaction, _arg3:String):int{
            if (!(_arg2 is TPerformVisitorHelp)){
                return (0);
            };
            var _local4:String = (_arg2 as TPerformVisitorHelp).getHelpType();
            if (_arg1 != _local4){
                return (0);
            };
            var _local5:GameObject = (_arg2 as TPerformVisitorHelp).getGameObject();
            var _local6 = "";
            if ((_local5 is HarvestableResource)){
                _local6 = (_local5 as HarvestableResource).getHarvestingDefinition().name;
            } else {
                _local6 = ((_local5 is ItemInstance)) ? (_local5 as ItemInstance).getItemName() : "";
            };
            return ((findNameInNames(_local6, _arg3)) ? 1 : 0);
        }
        public static function citySamHQ(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            var _local4:String = (_arg2) ? _arg2 : Player.FAKE_USER_ID_STRING;
            var _local5:int = Global.franchiseManager.getFranchiseCountByLocation(_local4);
            return (_local5);
        }
        public static function welcomeTrain(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (((_arg1 is TTrainWelcomeOrder)) ? 1 : 0);
        }
        public static function sendFranchiseSupply(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            if ((((_arg2 == null)) || ((_arg2 == "")))){
                return (((_arg1 is TFranchiseSupply)) ? 1 : 0);
            };
            return (((((_arg1 is TFranchiseSupply)) && (findNameInNames((_arg1 as TFranchiseSupply).franchiseType, _arg2)))) ? 1 : 0);
        }
        public static function countTransactionByCommodityUsedHelper(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            var _local4:int;
            var _local5:TOpenBusiness;
            var _local6:Boolean;
            var _local7:Business;
            var _local8:int;
            if ((((_arg2 == null)) || ((_arg2 == "")))){
                return (((_arg1 is TOpenBusiness)) ? 1 : 0);
            };
            _local4 = 0;
            _local5 = (_arg1 as TOpenBusiness);
            if (_local5){
                _local6 = (_local5.desiredCommodity == _arg2);
                _local7 = (_local5.getWorldObject() as Business);
                _local8 = _local7.getSupply(_arg2);
                if (((_local6) && ((_local8 > 0)))){
                    _local4 = 1;
                };
            };
            return (_local4);
        }
        public static function sendTrain(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (((_arg1 is TSendTrain)) ? 1 : 0);
        }
        public static function visitorHelp(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            var _local4:TPerformVisitorHelp;
            if ((_arg1 is TPerformVisitorHelp)){
                _local4 = (_arg1 as TPerformVisitorHelp);
                if (_local4.getHelpType() == _arg2){
                    return (1);
                };
            };
            return (0);
        }
        public static function consumeItemsAtInit(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            var _local6:Array;
            var _local7:String;
            var _local8:Item;
            var _local4:int;
            var _local5:int;
            if ((_arg1 is TPingFeedQuests)){
                _local6 = breakApartNames(_arg2);
                for each (_local7 in _local6) {
                    _local8 = Global.gameSettings.getItemByName(_local7);
                    if (_local8 != null){
                        _local4 = Global.player.inventory.getItemCount(_local8);
                        if (_local4 > 0){
                            _local5 = (_local5 + _local4);
                            Global.player.inventory.removeItems(_local7, _local4);
                        };
                    };
                };
            };
            return (_local5);
        }
        public static function checkItemsAtInit(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            var _local6:String;
            var _local7:Item;
            var _local4:int;
            var _local5:Array = breakApartNames(_arg2);
            for each (_local6 in _local5) {
                _local7 = Global.gameSettings.getItemByName(_local6);
                if (_local7 != null){
                    _local4 = (_local4 + Global.player.inventory.getItemCount(_local7));
                };
            };
            return (_local4);
        }
        public static function finishConstructionByClass(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            if (!(_arg1 is TConstructionFinish)){
                return (0);
            };
            var _local4:WorldObject = (_arg1 as TWorldState).getWorldObject();
            var _local5:ConstructionSite = (_local4 as ConstructionSite);
            if (_local5 == null){
                return (0);
            };
            var _local6:WorldObject = new _local5.targetClass(_local5.targetName);
            var _local7 = (("[object " + _arg2) + "]");
            var _local8:int = ((String(_local6))==_local7) ? 1 : 0;
            _local6.detach();
            _local6.cleanUp();
            return (_local8);
        }
        public static function countWorldObjectsHelper(_arg1:Array, _arg2:Transaction):int{
            var _local4:MapResource;
            var _local5:int;
            var _local6:MapResource;
            var _local7:Boolean;
            var _local3:int;
            if (((!(Global.isVisiting())) && (!(Global.isTransitioningWorld)))){
                _local4 = null;
                if ((Global.world.getTopGameMode() is GMPlaceMapResource)){
                    _local4 = (Global.world.getTopGameMode() as GMPlaceMapResource).displayedMapResource;
                };
                _local5 = 0;
                while (_local5 < _arg1.length) {
                    _local6 = (_arg1[_local5] as MapResource);
                    if (_local6 != null){
                        _local7 = ((!((_arg2 is TPlaceMapResource))) || (!((_local4.getItem().construction == null))));
                        if (((((!((_local4 == null))) && ((_local4.getId() == _local6.getId())))) && (_local7))){
                        } else {
                            _local3++;
                        };
                    };
                    _local5++;
                };
            };
            return (_local3);
        }
        public static function countWorldObjectByName(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            var _local5:Array;
            var _local6:String;
            var _local7:Array;
            var _local4:int;
            if (((!(Global.isVisiting())) && (!(Global.isTransitioningWorld)))){
                _local5 = breakApartNames(_arg2);
                for each (_local6 in _local5) {
                    _local7 = Global.world.getObjectsByNames([_local6]);
                    _local4 = (_local4 + countWorldObjectsHelper(_local7, _arg1));
                };
            };
            return (_local4);
        }
        public static function countWorldObjectByClass(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            var _local5:Class;
            var _local6:Array;
            var _local4:int;
            if (((!(Global.isVisiting())) && (!(Global.isTransitioningWorld)))){
                _local5 = (getDefinitionByName(("Classes." + _arg2)) as Class);
                _local6 = Global.world.getObjectsByClass(_local5);
                _local4 = countWorldObjectsHelper(_local6, _arg1);
            };
            return (_local4);
        }
        public static function countStorageObjects(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (Global.player.storageComponent.size);
        }
        public static function countStorageObjectsByType(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            var _local4:int;
            if (Global.player.storageComponent){
                _local4 = Global.player.storageComponent.getItemsByType(_arg2).length;
            };
            return (_local4);
        }
        public static function countCrewByItemName(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            var _local6:String;
            var _local7:int;
            var _local8:int;
            var _local9:Array;
            var _local10:GameObject;
            var _local4:Array = breakApartNames(_arg2);
            var _local5:int;
            for each (_local6 in _local4) {
                _local7 = 0;
                _local8 = 0;
                _local9 = Global.world.getObjectsByNames([_arg2]);
                for each (_local10 in _local9) {
                    _local8 = Global.crews.getCrewCountByObject(_local10);
                    if (_local8 > _local7){
                        _local7 = _local8;
                    };
                };
                _local5 = (_local5 + _local7);
            };
            return (_local5);
        }
        public static function countAnimalsObjects(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            if (!Global.world.getObjectsByNames([_arg2]).length){
                return (0);
            };
            return ((Global.world.getObjectsByNames([_arg2])[0] as ZooEnclosure).getAnimals());
        }
        public static function countConstructionOrBuildingByName(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            var _local5:Array;
            var _local6:Array;
            var _local7:ConstructionSite;
            var _local8:Array;
            var _local9:String;
            var _local4:int;
            if (((!(Global.isVisiting())) && (!(Global.isTransitioningWorld)))){
                _local5 = Global.world.getObjectsByClass(ConstructionSite);
                _local6 = new Array();
                for each (_local7 in _local5) {
                    if (findNameInNames(_local7.targetName, _arg2)){
                        _local6.push(_local7);
                    };
                };
                _local4 = (_local4 + countWorldObjectsHelper(_local6, _arg1));
                _local8 = breakApartNames(_arg2);
                for each (_local9 in _local8) {
                    _local5 = Global.world.getObjectsByNames([_local9]);
                    _local4 = (_local4 + countWorldObjectsHelper(_local5, _arg1));
                };
            };
            return (_local4);
        }
        public static function countPlayerResourceByType(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            var _local4:int;
            var _local5:int;
            var _local6:int;
            var _local7:Doober;
            switch (_arg2){
                case "coin":
                    _local4 = 0;
                    for each (_local7 in Global.world.dooberManager.doobers) {
                        if (_local7.getItem().type == Doober.DOOBER_COIN){
                            _local4 = (_local4 + _local7.amount);
                        };
                    };
                    return ((Global.player.gold + _local4));
                case "xp":
                    return (Global.player.xp);
                case "goods":
                    _local5 = 0;
                    for each (_local7 in Global.world.dooberManager.doobers) {
                        if (_local7.getItem().type == Doober.DOOBER_GOODS){
                            _local5 = (_local5 + _local7.amount);
                        };
                    };
                    return ((Global.player.commodities.getCount("goods") + _local5));
                case "premium_goods":
                    _local6 = 0;
                    for each (_local7 in Global.world.dooberManager.doobers) {
                        if (_local7.getItem().type == Doober.DOOBER_PREMIUM_GOODS){
                            _local6 = (_local6 + _local7.amount);
                        };
                    };
                    return ((Global.player.commodities.getCount("premium_goods") + _local6));
                case "population":
                    if (((!(Global.isVisiting())) && (!(Global.isTransitioningWorld)))){
                        return (Global.world.citySim.getScaledPopulation());
                    };
                    break;
                case "neighbors":
                    return (Global.player.neighbors.length);
            };
            return (0);
        }
        public static function countPlayerMapExpansions(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            return (Global.player.expansionsPurchased);
        }
        public static function completeCollectionByName(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            var _local6:String;
            var _local4:int;
            var _local5:Array = breakApartNames(_arg2);
            for each (_local6 in _local5) {
                if (Global.gameSettings.getCollectionByName(_local6).isReadyToTradeIn()){
                    _local4 = 1;
                    break;
                };
            };
            return (_local4);
        }
        public static function countCollectableByName(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            var _local6:String;
            var _local7:String;
            var _local4:int;
            var _local5:Array = breakApartNames(_arg2);
            for each (_local6 in _local5) {
                _local7 = Global.gameSettings.getCollectionByCollectableName(_local6).name;
                if (Global.player.collections.hasOwnProperty(_local7)){
                    if (Global.player.collections[_local7].hasOwnProperty(_local6)){
                        _local4 = (_local4 + Global.player.collections[_local7][_local6]);
                    };
                };
            };
            return (_local4);
        }
        public static function countFranchiseExpansionsByName(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            var _local4:int;
            var _local5:Array;
            var _local6:String;
            if ((((_arg2 == null)) || ((_arg2 == "")))){
                return (Global.franchiseManager.getAllFranchiseAcceptedLocationsCount());
            };
            _local4 = 0;
            _local5 = breakApartNames(_arg2);
            for each (_local6 in _local5) {
                _local4 = (_local4 + Global.franchiseManager.getFranchiseAcceptedLocationsCount(_local6));
            };
            return (_local4);
        }
        public static function countHeadquarters(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            var _local5:Array;
            var _local4:int;
            if (((!(Global.isVisiting())) && (!(Global.isTransitioningWorld)))){
                _local5 = Global.world.getObjectsByTypes([WorldObjectTypes.HEADQUARTER]);
                _local4 = countWorldObjectsHelper(_local5, _arg1);
            };
            return (_local4);
        }
        public static function incrementalPopulationCount(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            if (((!(_arg3)) || (!(_arg3.hasOwnProperty("incrementalPopulation"))))){
                _arg3.incrementalPopulation = Global.world.citySim.getScaledPopulation();
            };
            var _local4:int = Global.world.citySim.getScaledPopulation();
            var _local5:int = (_local4 - _arg3.incrementalPopulation);
            return (_local5);
        }
        public static function acceptTrain(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            if ((_arg1 is TAcceptTrain)){
                return (1);
            };
            return (0);
        }
        public static function captureBanditByID(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            var _local4:int;
            if ((((_arg1 is TCaptureBandit)) || ((_arg1 is TBuyCaptureBandit)))){
                _local4 = (_arg1 as TCaptureBandit).banditID;
                if ((((((_arg2 == null)) || ((_arg2 == "")))) || (findNameInNames(_local4.toString(), _arg2)))){
                    return (1);
                };
            };
            return (0);
        }
        public static function processPeddlerCenterUpgrade(_arg1:Transaction, _arg2:String, _arg3:Object=null):int{
            if ((_arg1 is TProgressPeddlerCenter)){
                return (1);
            };
            return (0);
        }

    }
}//package Modules.quest.Managers 
